package test12;

import com.tyfspring.aop.AdvisedSupport;
import com.tyfspring.aop.TargetSource;
import com.tyfspring.aop.aspectj.AspectJExpressionPointcut;
import com.tyfspring.aop.framework.Cglib2AopProxy;
import com.tyfspring.aop.framework.JdkDynamicAopProxy;
import org.junit.Test;

/**
 * @Description TODO
 * @Author shallow
 * @Date 2023/4/16 16:53
 */

public class test {
    @Test
    public void test_aop(){
        IUserService userService = new UserService();
        AdvisedSupport advisedSupport = new AdvisedSupport();
        advisedSupport.setTargetSource(new TargetSource(userService));
        advisedSupport.setMethodInterceptor(new UserServiceInterceptor());
        advisedSupport.setMethodMatcher(new AspectJExpressionPointcut("execution(* test12.IUserService.*(..))"));

        //代理对象
        IUserService proxy_jdk = (IUserService) new JdkDynamicAopProxy(advisedSupport).getProxy();
        //测试调用
        System.out.println("测试结果"+proxy_jdk.queryUserInfo());

        IUserService proxy_cglib = (IUserService) new Cglib2AopProxy(advisedSupport).getProxy();
        System.out.println("测试结果"+proxy_cglib.register("花花"));
    }
}
